import { z } from 'zod';

export const AppConfig = z.object({
  port: z.number({ coerce: true }).default(3000),
  version: z.string().default('dev'),
  commit: z.string().default('unknown'),

  heapUsedThreshold: z.number({ coerce: true }).default(150),
  rssThreshold: z.number({ coerce: true }).default(512),
});

export type AppConfigType = z.infer<typeof AppConfig>;

export default (): AppConfigType =>
  AppConfig.parse({
    port: process.env.PORT || 3000,
    version: process.env.VERSION || '1.0.0',
    commit: process.env.COMMIT,

    heapUsedThreshold: process.env.HEAP_USED_THRESHOLD,
    rssThreshold: process.env.RSS_THRESHOLD,
  });